<?php

class PondcasesHelper extends AppHelper {

	function getAging($date){
		$timedb = strtotime($date);
		$now = time();
		$differenz = round((($now - $timedb) / 60 / 60 / 24),0);

		IF($differenz >= 0 && $differenz < 8) { return "0 - 7 days"; }
		ELSEIF($differenz > 7 && $differenz < 15) { return "8 - 14 days"; }
		ELSEIF($differenz > 14 && $differenz < 22) { return "15 - 21 days"; }
		ELSEIF($differenz > 21) { return "< 21 days"; }
	}


	function getNewPR($caseid){
		$result = mysql_query("SELECT pr.detailnumber pr FROM pondcasehaspartrequests php, partrequests pr WHERE php.partrequest_id = pr.id AND php.pondcase_id = '$caseid'");
		$pr = mysql_fetch_object($result)->pr;
		return $pr;
	}


	function getColor($month){
		$start1 = date("Y-m-d H:i:s", mktime(0, 0, 0, $month, 1, 2011));
		$start2 = date("Y-m-d H:i:s", mktime(0, 0, 0, $month, 1, 2012));
		$end1 = date("Y-m-d H:i:s", mktime(23, 59, 59, $month, date("t"), 2011));
		$end2 = date("Y-m-d H:i:s", mktime(23, 59, 59, $month, date("t"), 2012));
		$result1 = mysql_query("SELECT COUNT(*) count FROM pondcases pc, partrequests pr LEFT JOIN customershasmacs chm ON (pr.mac_id = chm.mac_id) LEFT JOIN customers c ON (chm.customer_id = c.id) WHERE pc.partrequest_id = pr.id AND ((pc.createdate BETWEEN '$start1' AND '$end1') OR (pc.createdate BETWEEN '$start2' AND '$end2')) AND pc.status_id = 33");
		$result2 = mysql_query("SELECT COUNT(*) count FROM pondcases pc, partrequests pr LEFT JOIN customershasmacs chm ON (pr.mac_id = chm.mac_id) LEFT JOIN customers c ON (chm.customer_id = c.id) WHERE pc.partrequest_id = pr.id AND ((pc.createdate BETWEEN '$start1' AND '$end1') OR (pc.createdate BETWEEN '$start2' AND '$end2')) AND pc.status_id != 33");
		$count1 = mysql_fetch_object($result1)->count;
		$count2 = mysql_fetch_object($result2)->count;
		if($count1 == 0 && $count2 == 0) {
			return "#999999";
		}
		elseif($count1 == 0 && $count2 != 0) {
			return "#669900";
		}
		else {
			return "FF9900";
		}
	}


	function searchForComment($pondcase){
		$result = mysql_query("SELECT COUNT(*) count FROM comments WHERE pondcase_id = '$pondcase'");
		$count = mysql_fetch_object($result)->count;
		return $count;
	}


	function getCountPONDCases($mac){
		$result = mysql_query("SELECT COUNT(*) count FROM macs m, partrequests pr, pondcases pc WHERE m.mac = '$mac' AND m.id = pr.mac_id AND pr.id = pc.partrequest_id");
		$count = mysql_fetch_object($result)->count;
		return $count;
	}

    function getComment($pcid){
    	$result = mysql_query("SELECT comment FROM comments WHERE pondcase_id = '$pcid'");
    	$text = mysql_fetch_object($result)->comment;
    	return $text;
    }

}

?>
